package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.stanford.nlp.ling.Sentence;

import nlp.Segmenter;

/**
 * 分词servlet
 * @author Da Huang (dhuang.cn@gmail.com)
 *
 */
public class Segment extends HttpServlet {

	private static final long serialVersionUID = -7983747477650244285L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String rawIntel = new String(req.getParameter("intelligence").getBytes("ISO8859-1"), "UTF-8");
		HttpSession session = req.getSession();
		session.setAttribute("rawIntel", rawIntel);

		String segIntel = Sentence.listToString(Segmenter.getInstance().segment(rawIntel));
		session.setAttribute("segIntel", segIntel);
		
		req.getRequestDispatcher("index2.jsp").forward(req, resp);
	}
}
